import os
import time
from multiprocessing import Process
from threading import Thread


# 线程类
class MyThe(Thread):
    # 构造函数
    def __init__(self, name):
        super().__init__()
        self.name = name

    # 重写进程核心代码
    def run(self):
        print(f"{self.name}开始运行... {os.getpid()}", end="\n")
        time.sleep(3)
        print(f'{self.name}运行结束', end="\n")


# 进程类
class MyPro(Process):
    def run(self):
        print(f"B运行子进程 {os.getpid()}")
        t = MyThe("D子进程的子线程")
        t.start()
        print(f"C子进程的主线程开始运行qaq {os.getpid()}", end="\n")


if __name__ == '__main__':
    p = MyPro()
    p.start()
    print(f"A运行主进程 {os.getpid()}", end="\n")
